<template>
	<view class="certmain">
		<uni-nav-bar shadow title="" @clickLeft="back" height="88rpx" :border="false" :fixed="true"
			backgroundColor="#f8f8f8" :shadow="false" left-icon="left">
			<view class="input-view" style="background: white;width: 500rpx;">
				<uni-icons class="input-uni-icon" type="search" size="18" color="#999" />
				<input style="width: 500rpx;" class="uni-input" placeholder="输入搜索关键词" :value="inputClearValue"
					@input="clearInput" />
				<icon type="clear" v-if="showClearIcon" @click="clearIcon" size="16" />
			</view>
			<view @click="quxiao" style="position: absolute;right:44rpx;font-size:30rpx;top: 24rpx;">取消</view>
		</uni-nav-bar>
		<!-- <uni-nav-bar shadow title="电子书籍" @clickLeft="back" height="88rpx" :border="false" :fixed="true"
			backgroundColor="#FFFFFF" :shadow="false" left-icon="left"></uni-nav-bar> -->

		<view class="bookTab"  v-if="inputClearValue==''">
			<text class="left" @click="changeType(0)" :class="book_type=='0'?'focus':''">纸质书</text>
			<text class="right" @click="changeType(1)" :class="book_type=='1'?'focus':''">电子书</text>
		</view>
		<view class="container" v-if="showFlag == false">
			<view class="teainfo" v-for="(i,index) in AllList" :key="index">
				<view class="teatitle">
					<text class="t1">{{i.name}}</text>
					<!-- <text class="t2" v-show="i.study.length>0" @click="listMore(i)">更多></text> -->
				</view>
				<view class="teacon" v-show="i.child.length>0">
					<view class="tealeft" v-for="(item,n) in i.child" @click="toGoodsDetail(item)">
						<view class="timg">
							<image :src="item.image" mode=""></image>
						</view>
						<view class="">
							<text class="tt1">{{item.name}}</text>
						</view>
						<view class="tealeft—bom">
							<text v-if="item.book_type==1">电子书</text>
							<text v-else>纸质书</text>
							<text>{{item.goods_comment_count}}评论</text>
						</view>

					</view>
				</view>
				<view v-show="i.child.length==0" style="text-align: center;  margin: 20rpx;" class="">
					暂无内容
				</view>
			</view>
		</view>
		<view v-if="showFlag">
			<view style="margin-left: 20rpx;margin-top: 20rpx;">
				<view class="teainfo" v-for="(i,index) in AllList" :key="index">
					<view class="teacon" v-show="i.child.length>0">
						<view class="tealeft" v-for="(item,n) in i.child" @click="toGoodsDetail(item)"
							style="margin-top: 20rpx;">
							<view style="display: flex;">
								<view>
									<image style="width: 50px;height: 50px;" :src="item.image" mode=""></image>
								</view>
								<view
									style="margin-left: 30rpx;display: flex;justify-content: center;align-items: center;">

									<view style="font-size: 18px;font-weight: bold;width:460rpx;">
										<block v-for="(item2,n2) in item.name">
											<text style="color: #44a39e;"
												v-if="inputClearValue.includes(item2)  ">{{item2}}</text>
											<text v-else>{{item2}}</text>
										</block>
									</view>
									<view style="margin-left: 5rpx;">/</view>
									<view style="margin-left: 5rpx;">
										<text v-if="item.book_type==1">电子书</text>
										<text v-else>纸质书</text>
									</view>
								</view>
							</view>
							<view style="border: 1px solid #D8D8D8;width: 80%;margin-left: 110rpx;"></view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showFlag: false,
				inputClearValue: '',
				username: '',
				idcard: '',
				AllList: [],
				keyWord: '',
				showClearIcon: false,
				book_type: '0'
			}
		},
		onReady() {
			this.cx()
		},
		methods: {
			clearInput: function(event) {
				this.inputClearValue = event.detail.value;
				if (event.detail.value.length > 0) {
					this.showClearIcon = true;
				} else {
					this.showClearIcon = false;
				}
				this.showFlag = true
				this.cx()
			},
			clearIcon: function() {
				this.showFlag = false
				this.inputClearValue = '';
				this.showClearIcon = false;
				this.cx()
			},
			quxiao() {
				this.showFlag = false
				this.inputClearValue = '';
				this.showClearIcon = false;
				this.cx()
			},
			onInput(e) {
				this.keyWord = ''
				this.keyWord = e.target.value
				this.cx()
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
				
			changeType(type){
				this.book_type = type
				this.cx()
			},
			cx() {
				this.$api.post({
					url: '/book/bookListMobile',
					data: {
						keyWord: this.inputClearValue,
						book_type: this.book_type
					},
					success: res => {
						console.log(res);
						this.AllList = res;

						this.AllList.forEach(item => {})
					},
					fail: error => {
						console.log(error)
					}
				})
			},
			listMore(object) {
				console.log(object)
				// 加密传递的对象数据
				let item = encodeURIComponent(JSON.stringify(object))
				uni.navigateTo({
					url: '/pages/teacher/FreeStudyList?item=' + item,
				})

			},
			getDeatil(object) {
				console.log(object)
				// 加密传递的对象数据
				uni.navigateTo({
					url: '/pages/teacher/FreeStudyVideo?id=' + object.id + '&name=' + object.name,

				})
			},
			toJoin(item) {
				uni.navigateTo({
					url: '/pages/teacher/JoinICoperation',

				})
			},
			toGoodsDetail(item) {
				if (item.book_type == 1) {
					uni.navigateTo({
						url: "/pages/teacher/eBooksVideo?id=" + item.id
					})
				} else {
					uni.navigateTo({
						url: "/pages/product/goods?id=" + item.wanlshop_goods_id
					})
				}

			},
			// 分享回调
			wanlShare(e) {
				if (e) {
					this.$wanlshop.auth(`/pages/user/complaint/complaint?id=${this.goodsData.id}&type=3`);
				} else {
					this.modalName = null;
				}
			}
		}
	}
</script>

<style lang="scss">
	.certmain {
		width: 100%;
		// background-color: #FFFFFF;
		padding-bottom: 40rpx;

		/deep/.uni-nav-bar-text {
			font-size: 36rpx;
			color: #333333;
			font-weight: 800;
		}

		/deep/.uni-navbar__header-btns-left {
			width: 20px !important;
		}

		// /deep/.uni-input {
		//     height: 28px;
		//     line-height: 28px;
		//     font-size: 15px;
		//     padding: 0px;
		//     flex: 1;
		//     background-color: #FFFFFF;
		// }
		// /deep/.uni-icon {
		//         font-family: uniicons;
		//         font-size: 24px;
		//         font-weight: normal;
		//         font-style: normal;
		//         width: 24px;
		//         height: 24px;
		//         line-height: 24px;
		//         color: #999999;
		//     }
		.container {
			.teainfo {
				padding: 0 30rpx;

				.teatitle {
					display: flex;
					justify-content: space-between;
					margin-top: 40rpx;

					.t1 {
						font-size: 32rpx;
						font-weight: bold;
					}

					.t2 {
						font-size: 20rpx;
						font-weight: 400;
						color: #777777;
					}
				}

				.teacon {

					margin-top: 20rpx;
					display: flex;
					justify-content: space-between;
					flex-wrap: wrap;


					.tealeft,
					.tearight {
						width: 48%;
						background: #fff;
						opacity: 1;
						border-radius: 5px;
						background-color: #fff;
						margin-top: 20rpx;
						box-sizing: border-box;
						text-align: center;
						overflow: hidden;

						.timg {
							width: 100%;
							height: 320rpx;
							margin: 0 auto;
							background: rgba(255, 255, 255, 0.39);
							// border: 1px solid #707070;

							image {
								width: 100%;
								height: 100%;
							}
						}

						.tt1 {
							font-weight: bold;
							display: block;
							margin: 0 10rpx;
							margin-top: 16rpx;
							font-size: 28rpx;
							color: #333333;
							font-weight: 400;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							text-align: left;
						}

						.desc {
							font-size: 24rpx;
							font-family: PingFang SC;
							font-weight: 400;
							line-height: 36rpx;
							color: #333333;
						}

						.tealeft—bom {
							padding: 20rpx;
							display: flex;
							align-items: center;
							justify-content: space-between;
							margin-top: 10rpx;

							text:first-child {
								color: #ee0000;
							}
						}

						.tinfo {
							display: flex;
							justify-content: space-between;
							padding: 0 10rpx;
							margin-top: 14rpx;

							.yan,
							.san {
								display: inline-block;
								width: 16rpx;
								height: 20rpx;

								image {
									width: 100%;
									height: 100%;
								}
							}

							.san {
								margin-left: 30rpx;
							}

							.yy {
								width: 100rpx;
								height: 36rpx;
								font-size: 22rpx;
								color: #FFFFFF;
								background: rgba(231, 186, 119, 1);
								text-align: center;
								padding: 3rpx;
							}
						}
					}
				}
			}
		}
	}

	.bookTab {
		text-align: center;
		.left{
			background: #e2e2e2;
			padding: 4rpx 16rpx;
			line-height: 54rpx;
			border-radius:  54rpx 0 0 54rpx;
		}
		.right{
			margin-left: 10rpx;
			    background: #e2e2e2;
			    padding: 4rpx 16rpx;
			    line-height: 54rpx;
			    border-radius: 0 54rpx 54rpx 0;
		}
		.focus{
			background: #F29701;
			color: #FFFFFF;
			font-weight: 500;
		}
	}
</style>
